local EquipCard = class("EquipCard")

function EquipCard:ctor()
end

function EquipCard:setCallback(callback)
    self._callback = callback
end

function EquipCard:awake()
    G_UIUtil.addTouchEvent(self._panelTouch.transform, nil, nil, handler(self, self._onCheckClick))
    -- self._btnCheck.isOn = false
    -- self._btnCheck.onValueChanged:AddListener(handler(self, self._onCheckClick))
end

function EquipCard:updateUI(unit, selectId)
    self._unit = unit
    self._btnCheck.isOn = (unit:getId() == selectId)
    local config = unit:getConfig()
    self._textName.text = config.name
    self._textLevel.text = Lang.get("common_lv", {level = unit:getLevel()})
    self._imageIcon.sprite = G_ResourceManager:loadSprite("EquipAltas", config.res)
end

function EquipCard:_onCheckClick(selected)
    if not self._unit then
        return
    end
    if self._callback then
        self._callback(self._unit:getId())
    end
end

return EquipCard
